package com.gxa.modules.service.impl;

import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.PageRecv;
import com.gxa.common.vo.R;
import com.gxa.modules.mapper.ExpiringMapper;
import com.gxa.modules.pojo.Collection;
import com.gxa.modules.pojo.Loan;
import com.gxa.modules.pojo.Remind;
import com.gxa.modules.service.ExpiringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExpiringServiceImpl implements ExpiringService {
    @Autowired(required = false)
    private ExpiringMapper expiringMapper;
    @Override
    public JsonResult queryLoanZ(Integer page, Integer limit) {
        JsonResult jsonResult = new JsonResult();
        Integer param1 = (page - 1)*limit;
        Integer param2 = limit;
        List<Loan> collectionMap = expiringMapper.queryLoanZ(param1,param2);
        int result = expiringMapper.countLoanZ();
        jsonResult.setCount(result);
        jsonResult.setData(collectionMap);
        jsonResult.setCode(200);
        jsonResult.setMsg("查询成功");
        return jsonResult;
    }

    @Override
    public JsonResult queryLoanZList(PageRecv<Loan> pageRecv) {
        //对查询页面参数计算
        Integer currentPage=pageRecv.getCurrentPage();
        Integer pageSize=pageRecv.getPageSize();
        Integer limit1=(currentPage-1)*pageSize;
        pageRecv.setCurrentPage(limit1);
        Loan loan=pageRecv.getData();
        List<Loan>loanList=expiringMapper.queryLoanZList(pageRecv);
        Integer count =expiringMapper.countLoanZList(pageRecv);
        JsonResult r=new JsonResult();
        r.setCode(200);
        r.setCount(count);
        r.setMsg("查询成功");
        r.setData(loanList);
        return r;
    }

    @Override
    public JsonResult updateExpiring(Remind remind) {
        JsonResult jsonResult=new JsonResult();
        List<Remind>remindList=expiringMapper.selectExpiring(remind);
         jsonResult.setData(remindList);
        if(remindList == null){
            expiringMapper.addExpiring(remind);
            jsonResult.setCode(200);
            jsonResult.setMsg("添加成功！");
        }else {
            expiringMapper.updataExpiring(remind);
            jsonResult.setCode(200);
            jsonResult.setMsg("修改成功！");
        }
        return jsonResult;

    }
}
